package   org.platform.core.filecommand.util;

import java.io.File;
import java.util.Collection;
import java.util.Iterator;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.FileFilterUtils;
import org.apache.commons.lang3.StringUtils;

public class FileNameIndexUtils {
	@SuppressWarnings("unchecked")
	public static String getFileName(String dir,String fileName){
		int j = 1;
		File file = new File(dir);
		if (!file.exists()) {
			file.mkdirs();
		}
		Collection<File> files = FileUtils.listFiles(file, FileFilterUtils.suffixFileFilter("xml"), null);
		for (Iterator<File> i = files.iterator(); i.hasNext();)
		{
			File getFile = (File) i.next();
			if(fileName.equals(getFile.getName())){
				++j;
			}
		}
		String[] splitName = fileName.split("_");
		return StringUtils.join(splitName[0],"_",splitName[1],"_",splitName[2],"_",splitName[3],"_","00",j,".xml");
	}
}
